<?php
use yii\helpers\Html;
$this->params['breadcrumbs'][] = $this->title;
?>
<style>
    .pagenum{
        width: 50px;
        text-align: center;
    }
    .mysearch{
        width: 60px;
        text-align: center;
    }
</style>
<div class="site-agents">
    <div class="agents-list">
        <ul id="mylist">

        </ul>
    </div>

    <div class="page">
        <?= Html::button('上一页', ['id' => 'mypreage']) ?>
        <?= Html::input('text', 'page',1, ['id' =>'curpage','readonly'=>true,'class'=>'pagenum']) ?>
        <?= Html::button('下一页', ['id' => 'mynextage']) ?>
        <?= Html::input('text', 'searchinput','', ['id' =>'searchinput','class'=>'mysearch']) ?>
        <?= Html::button('搜索', ['id' => 'mysearch']) ?>
    </div>
</div>
<?php $this->beginBlock('myjs') ?>

<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['myjs'], \yii\web\View::POS_READY); ?>
<script>
    function getdata(airline,page) {
        $.ajax({
            type: "POST",
            url: '<?=\Yii::getAlias('@web')?>/ajax/ajaxagents',
            dataType: "json",
            data:
                {
                    airline:airline,
                    page:page,
                },
            success: function(data)
            {
                $("#curpage").val(parseInt(data.page)+1);
                $("#mylist").empty();
                for(var i=0;i<data.agents.length;i++)
                {
                    $("#mylist").append("<li>"+data.agents[i]['buy_nbr']+"</li>");
                }
            },
            error: function(jqXHR)
            {
                alert("发生错误：" + jqXHR.status);
            },
        });
    }
    getdata("<?=$airline?>",0);
    $("#mypreage").click(function(){
        var curpage=$("#curpage").val();
        getdata("<?=$airline?>",parseInt(curpage)-1-1);
    });
    $("#mynextage").click(function(){
        var curpage=$("#curpage").val();
        getdata("<?=$airline?>",parseInt(curpage)-1+1);
    });
    $("#mysearch").click(function(){
        var curpage=$("#searchinput").val();
        getdata("<?=$airline?>",parseInt(curpage)-1);
    });
</script>
